package com.itmq;


import jdk.nashorn.internal.ir.annotations.Reference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;

import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Session;

/**
 * 它是真正发消息的工具类
 */
@Component("productDemo")
public class ProductDemo {
    @Autowired
    private JmsTemplate jmsTemplate;
    @Autowired
    private Destination destination;

    //参数就是要发送的消息
    public void sendMessage(String message) {
        //send方法参数1是目的地  参数2：自动发送消息
        jmsTemplate.send(destination, new MessageCreator() {
            @Override
            public Message createMessage(Session session) throws JMSException {
                return session.createTextMessage(message);
            }
        });
    }

}
